package com.life.wd.controller;

import com.life.wd.dto.OrderDTO;
import com.life.wd.result.PageResult;
import com.life.wd.result.Result;
import com.life.wd.service.OrderService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/order")
@Slf4j
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping
    public Result<PageResult> select(@RequestBody OrderDTO orderDTO) {
        log.info("查询订单：{}",orderDTO);
        PageResult orders = orderService.pageQuery(orderDTO);
        return Result.success(orders);
    }

    /**
     * 发货订单
     * @param id 订单id
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Long id) {
        log.info("发货订单：{}",id);
        int result = orderService.update(id);
        if (result > 0) {
            return Result.success("订单发货成功");
        } else {
            return Result.error("订单发货失败，或订单不存在");
        }
    }
}
